//
//  GVMessageMusicView.m
//  GmallVIP
//
//  Created by yemeihua on 15/11/4.
//  Copyright © 2015年 yemeihua. All rights reserved.
//

#import "GVMessageMusicView.h"

@implementation GVMessageMusicView

- (instancetype)init
{
    if(self = [super init])
    {
        self.backgroundColor = [UIColor whiteColor];
        
        _typeImageView = [[UIImageView alloc] init];
        _typeImageView.contentMode = UIViewContentModeScaleAspectFill;
        _typeImageView.layer.masksToBounds = YES;
        _typeImageView.image = [UIImage imageNamed:@"msg_music"];
        [self addSubview:_typeImageView];
        
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.layer.masksToBounds = YES;
        _imageView.userInteractionEnabled = YES;
        [self addSubview:_imageView];
        
        _typeLabel = [[UILabel alloc] init];
        _typeLabel.textColor = [UIColor blackColor];
        _typeLabel.backgroundColor = [UIColor whiteColor];
        _typeLabel.font = [UIFont systemFontOfSize:21];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.text = @"音乐";
        [self addSubview:_typeLabel];
        
        _stateImageView = [[UIImageView alloc] init];
        _stateImageView.image = [UIImage imageNamed:@"msg_music_play"];
        _stateImageView.userInteractionEnabled = YES;
        [_imageView addSubview:_stateImageView];
        
        _indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        [_stateImageView addSubview:_indicatorView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_titleLabel];
        
        _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
        _progressView.trackTintColor = [UIColor lightGrayColor];
        _progressView.progressTintColor = [UIColor blackColor];
        _progressView.progress = 0.0;
        [self addSubview:_progressView];
        
        [_typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.equalTo(@0);
        }];
        
        [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.right.equalTo(@0);
        }];
        
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.equalTo(_typeImageView.mas_bottom).offset(10);
            make.width.and.height.equalTo(@([GVMessageMusicView width]));
        }];
        
        [_stateImageView  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(_imageView);
        }];
        
        [_indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(_stateImageView);
        }];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageView.mas_bottom).offset(15);
            make.left.equalTo(@0);
            make.width.equalTo(_imageView.mas_width);
        }];
        
        [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(10);
            make.left.equalTo(@0);
            make.width.equalTo(_imageView.mas_width);
        }];
    }
    return self;
}

+ (CGFloat)width
{
    static CGFloat width = 0;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        width = 0.69 * kScreenWidth;
    });
    return width;
}

@end
